////////////////////////////////////////////////////////////////////////////////
//  COPYRIGHT (C) 2010 TELECOM DIGITAL MEDIA ("TDMEDIA").
//  ALL RIGHTS RESERVED.
//
//  THIS IS CONFIDENTIAL AND PROPRIETARY INTELLECTUAL PROPERTY OWNED BY AND
//  CREATED ON BEHALF OF TDMEDIA. ANY FORM OF DISTRIBUTION, COPY,
//  MODIFICATION WITHOUT THE WRITTEN CONSENT FROM TDMEDIA IS STRICTLY
//  PROHIBITED.
////////////////////////////////////////////////////////////////////////////////
package cc.telecomdigital.tdstock.activity.groups.more;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import cc.telecomdigital.tdstock.CommonDefn;
import cc.telecomdigital.tdstock.ITDLApplication;
import cc.telecomdigital.tdstock.R;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;
import cc.telecomdigital.tdstock.Tools.ActivityGroupController;
import cc.telecomdigital.tdstock.activity.BaseActivity;
import cc.telecomdigital.tdstock.activity.groups.MoreGroup;
import cc.telecomdigital.tdstock.adapter.CommonListItemAdapter;
import cc.telecomdigital.tdstock.adapter.CommonViewHolder;

/**
 * 
 * @author haibo
 * 
 *  for list item  named  "AH Comparison"
 *
 */
public class StockAnalysisActivity extends BaseActivity
{
	protected static final String	TAG	= StockAnalysisActivity.class.getSimpleName();
	
	private TextView[]			_txt;
	private Drawable[]			_sign;
	private ListView			_listView;
	private Button				_toolBtnReturn;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.stock_analysis);
		
		_toolBtnReturn = (Button) findViewById(R.id.more_returnbtn);
		_toolBtnReturn.setFocusable(true);
		_toolBtnReturn.setClickable(true);
		_toolBtnReturn.setOnClickListener(new OnClickListener()
		{
			@Override
			public void onClick(View v)
			{
				TDStockLog.d(TAG, "close current activity and forwarding to the previous");

				Intent intent = new Intent(getApplicationContext(), MoreActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
				SwitchForwardActivity(MoreActivity.class, intent);
			}
		});

		_listView = (ListView) findViewById(R.id.more_stock_analysis_list);

		final String[] txtRes = this.getResources().getStringArray(R.array.stock_analysis);
		int listSize = txtRes.length;
		_txt = new TextView[listSize];
		_sign = new Drawable[listSize];
		for (int index = 0; index < listSize; index++)
		{
			TextView title = new TextView(this);
			title.setText(txtRes[index]);
			_txt[index] = title;
			_sign[index] = this.getResources().getDrawable(R.drawable.go_next_icon);
		}

		List<CommonViewHolder> list = new ArrayList<CommonViewHolder>();
		for (int index = 0; index < listSize; index++)
		{
			CommonViewHolder viewHolder = new CommonViewHolder();
			viewHolder.id = index;
			viewHolder.text = _txt[index];
			viewHolder.sign = new ImageView(this);
			viewHolder.sign.setImageDrawable(_sign[index]);

			list.add(viewHolder);
		}
		_messageHandler = null; //this activity no need it.
		_listView.setAdapter(new CommonListItemAdapter(LayoutInflater.from(this), list));
		_listView.setOnItemClickListener(new OnItemClickListener()
		{
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id)
			{
				if (position != -1)
				{
					((ITDLApplication) getApplicationContext()).putString(CommonDefn.TOP_BAR_TITLE, txtRes[position]);
					((ITDLApplication) getApplicationContext()).setId(position);
					
					StockAnalysisContentActivity.iTypeId = position;
					Intent intent = new Intent(getApplicationContext(), StockAnalysisContentActivity.class);
					intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_NO_USER_ACTION);
					SwitchForwardActivity(StockAnalysisContentActivity.class, intent);
				}
			}
		});
	}
	
	@Override
	public void onResume()
	{
		super.onResume();
		_listView.invalidateViews();
	}
	
	@Override
	public ActivityGroupController GetActivityGroupController()
	{
		return MoreGroup.GetActivityGroupHostControl();
	}
}
